package com.boco.modules.fdoc.web.hosperformance;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.boco.common.web.ServletController;
import com.boco.modules.fdoc.service.HosPerformanceService;
import com.boco.modules.fdoc.vo.HosPerformanceVo;

@Controller
@RequestMapping(value = "/hosperformance", produces = "text/json;charset=utf-8")
public class HosPerformanceAction extends ServletController{
	
	@Resource
	HosPerformanceService hosPerformanceService;
	
	//查询需要在表格中展示的服务包
	@RequestMapping(value = "/querySigPacks")
	@ResponseBody
	public String querySigPacks(){
		String jsonData = "";
		try {
			String packs = hosPerformanceService.querySigPack();
			jsonData = "{\"success\":true,\"result\":"+packs+"}";
		} catch (Exception e) {
			logger.error("查询需要在表格中展示的服务包失败", e);
			jsonData = "{\"success\":false,\"result\":\""+e.getCause().toString().replaceAll("###", "").replaceAll("\n", "")+"\"}";
		}
		return jsonData;
	}
	
	//查询医院的绩效信息
	@RequestMapping(value = "/queryPerformance")
	public ModelAndView queryPerformance() {
		try {
			HosPerformanceVo vo = hosPerformanceService.queryPerformance();
			return new ModelAndView("/hosperformance/hosperformance")
					.addObject("page", vo);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询医院的绩效信息失败", e);
			//返回界面，提示错误信息
			return new ModelAndView("/hosperformance/hosperformance").addObject("errorInfo", "查询医院的绩效信息失败");
		}
	}
	
	//查询当前服务包下的居民信息
	@RequestMapping(value = "/queryResident")
	@ResponseBody
	public String queryResident(int hosId,int sigId){
		String jsonData = "";
		try {
			HosPerformanceVo vo = new HosPerformanceVo();
			vo.setHosId(hosId);
			vo.setSigId(sigId);
			String resident = hosPerformanceService.queryResident(vo);
			jsonData = "{\"success\":true,\"result\":"+resident+"}";
		} catch (Exception e) {
			logger.error("查询当前服务包下的居民信息失败", e);
			jsonData = "{\"success\":false,\"result\":\""+e.getCause().toString().replaceAll("###", "").replaceAll("\n", "")+"\"}";
		}
		return jsonData;
	}
	
	

}
